package com.ruoyi.wm.service.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wm.domain.WmDoctors;
import com.ruoyi.wm.domain.WmDrivers;
import com.ruoyi.wm.domain.WmNurses;
import com.ruoyi.wm.mapper.WmDoctorsMapper;
import com.ruoyi.wm.mapper.WmDriversMapper;
import com.ruoyi.wm.mapper.WmNursesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wm.mapper.WmStatisticsMapper;
import com.ruoyi.wm.domain.WmStatistics;
import com.ruoyi.wm.service.IWmStatisticsService;
import com.ruoyi.common.core.text.Convert;

/**
 * 成本核算Service业务层处理
 * 
 * @author hpf
 * @date 2021-12-05
 */
@Service
public class WmStatisticsServiceImpl implements IWmStatisticsService 
{
    @Autowired
    private WmStatisticsMapper wmStatisticsMapper;
    @Autowired
    private WmDoctorsMapper wmDoctorsMapper;
    @Autowired
    private WmNursesMapper wmNursesMapper;
    @Autowired
    private WmDriversMapper wmDriversMapper;

    /**
     * 查询成本核算
     * @param id 成本核算ID
     * @return 成本核算
     */
    @Override
    public WmStatistics selectWmStatisticsById(Long id)
    {
        return wmStatisticsMapper.selectWmStatisticsById(id);
    }

    /**
     * 查询成本核算列表
     * 
     * @param wmStatistics 成本核算
     * @return 成本核算
     */
    @Override
    public List<WmStatistics> selectWmStatisticsList(WmStatistics wmStatistics)
    {
        return wmStatisticsMapper.selectWmStatisticsList(wmStatistics);
    }

    /**
     * 新增成本核算
     * 
     * @param wmStatistics 成本核算
     * @return 结果
     */
    @Override
    public int insertWmStatistics(WmStatistics wmStatistics)
    {
        wmStatistics.setCreateTime(DateUtils.getNowDate());
        return wmStatisticsMapper.insertWmStatistics(wmStatistics);
    }

    /**
     * 修改成本核算
     * 
     * @param wmStatistics 成本核算
     * @return 结果
     */
    @Override
    public int updateWmStatistics(WmStatistics wmStatistics)
    {
        return wmStatisticsMapper.updateWmStatistics(wmStatistics);
    }

    /**
     * 删除成本核算对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWmStatisticsByIds(String ids)
    {
        return wmStatisticsMapper.deleteWmStatisticsByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除成本核算信息
     * 
     * @param id 成本核算ID
     * @return 结果
     */
    @Override
    public int deleteWmStatisticsById(Long id)
    {
        return wmStatisticsMapper.deleteWmStatisticsById(id);
    }

    @Override
    public int insertWmStatisticsEveryMonth() {
        ArrayList<WmDoctors> doctors = (ArrayList<WmDoctors>) wmDoctorsMapper.selectWmDoctorsList(new WmDoctors());//获取医生列表
        ArrayList<WmDrivers> drivers = (ArrayList<WmDrivers>) wmDriversMapper.selectWmDriversList(new WmDrivers());//获取司机列表
        ArrayList<WmNurses> nurses = (ArrayList<WmNurses>) wmNursesMapper.selectWmNursesList(new WmNurses());//获取护士列表
        Calendar calendar = Calendar.getInstance();
        String year = Integer.toString(calendar.get(Calendar.YEAR));
        String month = Integer.toString(calendar.get(Calendar.MONTH)+1);
        for(WmDoctors doctor:doctors){
            WmStatistics statistic = new WmStatistics();
            statistic.setName(doctor.getName());//设置名字
            statistic.setMonth("1");//设置月份
            statistic.setYear(year);//设置时间
            statistic.setCreateTime(new Date());//设置创建时间
            wmStatisticsMapper.insertWmStatistics(statistic);//插入
        }
        for(WmNurses nurse:nurses){
            WmStatistics statistic = new WmStatistics();
            statistic.setName(nurse.getName());
            statistic.setMonth("1");
            statistic.setYear(year);
            statistic.setCreateTime(new Date());
            wmStatisticsMapper.insertWmStatistics(statistic);
        }
        for(WmDrivers driver:drivers){
            WmStatistics statistic = new WmStatistics();
            statistic.setName(driver.getName());
            statistic.setMonth("1");
            statistic.setYear(year);
            statistic.setCreateTime(new Date());
            wmStatisticsMapper.insertWmStatistics(statistic);
        }
        return 1;
    }
}
